import { Injectable } from '@nestjs/common'
import { InjectRepository } from '@nestjs/typeorm'
import { Repository } from 'typeorm'
import { CreatePlanTaskDto } from './dto/create-plan-task.dto'
import { UpdatePlanTaskDto } from './dto/update-plan-task.dto'
import { PlanTaskEntity } from './plan-task.entity'

@Injectable()
export class PlanTaskService {
  constructor(
    @InjectRepository(PlanTaskEntity)
    private readonly planTaskRepository: Repository<PlanTaskEntity>,
  ) {}

  async create(createPlanTaskDto: CreatePlanTaskDto) {
    const planTask = this.planTaskRepository.create(createPlanTaskDto)
    return this.planTaskRepository.save(planTask)
  }

  async replace(createPlanTaskDto: CreatePlanTaskDto) {
    const planTask = this.planTaskRepository.create(createPlanTaskDto)
    return this.planTaskRepository.save(planTask)
  }

  async findAll() {
    return this.planTaskRepository.find()
  }

  async findOne(id: number) {
    return this.planTaskRepository.findOne({
      where: { id },
    })
  }

  async update(id: number, updatePlanTaskDto: UpdatePlanTaskDto) {
    return this.planTaskRepository.update(id, updatePlanTaskDto)
  }

  async remove(id: number) {
    return this.planTaskRepository.delete(id)
  }
}
